/*package com.ym.b2b.payment.controller.bocPay;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.ym.b2b.commons.conf.B2BConstants;
import com.ym.b2b.commons.conf.WebTokenUser;
import com.ym.b2b.commons.controller.BaseController;
import com.ym.b2b.commons.exception.BaseException;
import com.ym.b2b.commons.util.CheckData;
import com.ym.b2b.order.DefaultTradeRequestImpl;
import com.ym.b2b.order.TradeRequest;
import com.ym.b2b.order.dao.EmSOrderConfirmItemDao;
import com.ym.b2b.order.dao.EmSOrderDao;
import com.ym.b2b.order.sqlbean.EmSOrder;
import com.ym.b2b.order.sqlbean.EmSOrderConfirmItem;
import com.ym.b2b.order.vo.OrderInfoVO;
import com.ym.b2b.order.xc.sqlbean.XCReturnModel;
import com.ym.b2b.payment.service.EmSPaymentService;
import com.ym.b2b.payment.sqlbean.EmSPayment;
import com.ym.b2b.payment.vo.PaymentBean;
import com.zc.commons.base.Result;

@Controller
@RequestMapping("/BOCPay")
public class BOCPayController extends BaseController {

	private static String bocNo									= 	"6124";
	private static String curCode								= 	"001";
	
	*//**
	 * 在cx/config/spring/med-context-bank中配置
	 *//*
    @Resource
    private BOCParam        bocParamBean;

    @Resource
	private BOCV1Params 	boc1Params;
    
    
    @Resource
    private TradeRequest	defaultTradeRequest;
     
    @Autowired
    private EmSOrderDao		emSOrderDao;
    @Autowired
    private EmSOrderConfirmItemDao emSOrderItemDao;

    @Autowired
    private EmSPaymentService	emSPaymentService;

    *//**
     * 中行支付(8.2.1.1商户发送B2B订单支付请求(非监管商户))
     * 订单列表点在线支付-->立即付款
     *//*
    @RequestMapping("getBOCPayInfoForFee.s")
    public ModelAndView getCCBPayInfoForFee(EmSOrder emSOrder, HttpServletRequest req) {
    	logger.info("----------进入中行支付接口, 传入参数: \n " + JSON.toJSONString(emSOrder));
    	ModelAndView m = new ModelAndView();
    	try {
            WebTokenUser token = getWebTokenUser(req);
            if (null == token) {
                m.setViewName(B2BConstants.WEB_NOT_LOGIN);
                return m;
            }
            // 组装需要塞入的订单信息
            EmSOrder s = emSOrderDao.searchOrderDetail(emSOrder);
            if (null == s || s.getStatus() >= 20) {
                m.addObject("info", "订单已经支付过了  不能重复提交!");
                m.setViewName(B2BConstants.WEB_ERROR);
                return m;
            }

            // 从XML中获取固定写死字段
            BOCParam bocParam = new BOCParam();
            BeanUtils.copyProperties(bocParam, bocParamBean);

            // 填充支付
            PaymentBean emSPaymentBean = new PaymentBean();
            emSPaymentBean.setOrderCode(s.getOrderCode());
            emSPaymentBean.setPaymentRequestIp(CheckData.getIpAddr(req));
            emSPaymentBean.setPaymentMoney(s.getConfirmMoney());
            Result ret = emSPaymentService.doPayBefore(emSPaymentBean);

            if (ret.getCode().equals("100")) {
                m.addObject("info", "订单支付请求 提交失败 请联系管理员!");
                m.setViewName(B2BConstants.WEB_ERROR);
                return m;
            }
        	SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
            bocParam.setOrderNo(s.getOrderCode());

            DecimalFormat df=new DecimalFormat("0.00");	// 金额要保留2位小数
            String orderAmount = df.format(s.getConfirmMoney());
            bocParam.setOrderAmount(orderAmount);
            bocParam.setOrderTime(sdf.format(new Date()));
            bocParam.setOrderNote("订单说明123");

            // 参数加签  bocNo|orderNo|curCode|orderAmount|orderTime
            String signPlaintext = bocNo + "|" + s.getOrderCode() + "|"
            		+ curCode + "|" + orderAmount + "|"
            		+ sdf.format(new Date());
            
            logger.info("参与加签的数据:\n " + signPlaintext);
			byte[] data = signPlaintext.getBytes();
			PKCS7Tool JQ4 = PKCS7Tool.getSigner("D:\\4.pfx", "boc111111", "boc111111");
			String signData = JQ4.sign(data);
			bocParam.setSignData(signData);

            m.addObject("bocParam", bocParam);
            logger.info("----------发送到支付网站的数据====BOC: \n " + JSON.toJSONString(bocParam));
            m.setViewName("/center/trade/pay/bocpay/post_do");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            m.setViewName(B2BConstants.WEB_ERROR);
        }
    	
    	return m;
    }
    // 银行返回
    @RequestMapping("recviceBOCPay.s")
	public ModelAndView recviceCCBPay(BOCBackParam receiveBean, HttpServletRequest req) {
		try {
			logger.info("接收支付网站回调参数====BOC：" + JSON.toJSONString(receiveBean));
			if ("01".equals(receiveBean.getTranCode())
					&& "1".equals(receiveBean.getTranStatus())) {
				// this.verify(receiveBean);

				// 更新订单状态 和 支付表数据
				SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");

				EmSOrder order = new EmSOrder();
				order.setOrderCode(receiveBean.getOrderNo());
				order.setFeeDate(receiveBean.getTranTime());
				order.setTranSerialNo(receiveBean.getTranSeq()); // 网关生成的交易流水
				// order.setFeeAmount(Double.parseDouble(receiveBean.getPayAmount())
				// / 100);
				order.setOrderType(1); // 在线付款
//	http://localhost:8888/xc/BOCPay/recviceBOCPay.s?tranCode=01&tranStatus=1&orderNo=16081810377467&tranTime=20160818161900&tranSeq=23333&tranAmount=7.8&curCode=001
				// ========================================= ERP相关处理start	=========================================
				// 在application_config.xml中控制判断什么时候对接ERP下订单 ,false 则在支付后下单,ture则在确认时下单
				if (!DefaultTradeRequestImpl.isBooking()) {
					// 根据orderCode查出订单信息,订单产品详情,并组装成ERP接口所需model
					EmSOrder orderForERP = emSOrderDao.searchOrderDetail(order);
					EmSOrderConfirmItem item = new EmSOrderConfirmItem();
					item.setOrderCode(receiveBean.getOrderNo());
					List<EmSOrderConfirmItem> listItem = emSOrderItemDao.searchEmSOrderConfirmItem(item);
					OrderInfoVO vo = makeOrderInfo(orderForERP, listItem);

					// 调用ERP create接口
					Result erpResult = defaultTradeRequest.bookingErpOrder(vo,null);
					if (!"200".equals(erpResult.getCode())) {
						logger.error("ERP下单失败:" + erpResult.getResult());
						throw new BaseException("ERP下单失败:"
								+ erpResult.getResult());
					}

					// *** ERP下单成功：更新erp系统的内部单据号 *******//*
					XCReturnModel xcReturnModel = (XCReturnModel) erpResult
							.getData().get("orderRet");
					if (null != xcReturnModel
							&& !"".equals(xcReturnModel.getOrderCode())) {
						String returnCode = xcReturnModel.getOrderCode();
						order.setOrderCodeErp(returnCode.substring(returnCode
								.indexOf("-") + 1));
					}
				} else {
					// 根据orderCode查出订单信息,订单产品详情,并组装成ERP接口所需model
					EmSOrder orderForERP = emSOrderDao.searchOrderDetail(order);
					EmSOrderConfirmItem item = new EmSOrderConfirmItem();
					item.setOrderCode(receiveBean.getOrderNo());
					List<EmSOrderConfirmItem> listItem = emSOrderItemDao.searchEmSOrderConfirmItem(item);
					OrderInfoVO vo = makeOrderInfo(orderForERP, listItem);

					// 调用ERP create接口
					defaultTradeRequest.updateOrder(vo,listItem);
				}
				// =========================================	ERP相关处理end	=========================================
				order.setStatus(Double.parseDouble("20")); // 已付款
				emSOrderDao.updateEmSOrder(order);

				EmSPayment payment = new EmSPayment();
				payment.setOrderCode(receiveBean.getOrderNo());
				payment.setPaymentFrom("PC");
				payment.setPaymentMedthod("中行");
				payment.setPaymentMoney(Double.parseDouble(receiveBean.getTranAmount()) / 100);
				payment.setPaymentCompleteDate(sf.parse(receiveBean.getTranTime()));
				payment.setPaymentStatus(1);
				payment.setDealFlag(1);

				emSPaymentService.updateEmSPayment(payment);
				System.out.println("商户订单处理完成");
			} else {
				System.out.println("商户订单处理失败");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		ModelAndView m = new ModelAndView();
		m.setViewName("index");
		return m;
	}
   // http://111.39.26.6/BOCPay/recviceBOCPay.s?tranCode=01&tranStatus=1&orderNo=16081810377467&tranTime=20160818161900&tranSeq=2&tranAmount=7.8&curCode=001
    // 银行返回结果验签
    private void verify(BOCBackParam receiveBean) throws Exception {
    	StringBuffer sb = new StringBuffer("");
        sb.append(receiveBean.getTranSeq() + "|");
        sb.append(receiveBean.getTranCode() + "|");
        sb.append(receiveBean.getTranStatus() + "|");
        sb.append(receiveBean.getTranTime() + "|");
        sb.append(receiveBean.getTranAmount() + "|");
        sb.append(receiveBean.getFeeAmount() + "|");
        sb.append(receiveBean.getBocNo() + "|");
        sb.append(receiveBean.getOrderNo() + "|");
        sb.append(receiveBean.getCurCode());
		String signPlaintext = sb.toString();
		byte[] data = signPlaintext.getBytes();

		PKCS7Tool YQ4 = PKCS7Tool.getVerifier("D:\\4.cer");
		YQ4.verify(receiveBean.getSignData(), data, "CN=测试商户, OU=TEST, O=BANK OF CHINA, C=CN");

    }
    
    private OrderInfoVO makeOrderInfo(EmSOrder orderForERP,List<EmSOrderConfirmItem> list){
    	OrderInfoVO vo = new OrderInfoVO();
    	vo.setOrderCode(orderForERP.getOrderCode());
    	vo.setBuyerCode(orderForERP.getBuyerCode());
    	WebTokenUser user = new WebTokenUser();
    	user.setBuyerCode(orderForERP.getBuyerCode());
    	vo.setErpCode(orderForERP.getOrderCodeErp());
    	vo.setUser(user);
    	vo.setSalesman(orderForERP.getSalesman());
    	vo.setEmSOrderConfirmItemList(list);
    	return vo;
    }
}
*/